package canss.webservice.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.beehive.controls.api.bean.Control;

import canss.webservice.model.EventDescription;
import canss.webservice.service.PortalIntraWebServiceControl;

import weblogic.application.utils.XMLWriter;
import canss.webservice.service.PortalIntraWebServiceControlBean;

public class svtOPAdminEventDesc extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet
{
	private static final long serialVersionUID = -8315366814268536184L;
	@Control
	PortalIntraWebServiceControl control; // control = (control==null)?new

	// PortalIntraWebServiceControlBean():control;

	public svtOPAdminEventDesc()
	{
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();

		String _notxml = request.getParameter("_notxml");

		if (_notxml != null)
		{// in html
			out.write("doesn't support raw html.<br/>");

		} else
		{
			out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
			XMLWriter writer = new XMLWriter(out);

			writer.addElement("canss");
			writer.addElement("canssEvent_eventGroup");
			{
				control = (control == null) ? new PortalIntraWebServiceControlBean() : control;
				EventDescription[] eventdesclist = control.getEntireEventDesc();
				if (eventdesclist != null && eventdesclist.length > 0)
				{
					for (EventDescription eventdesc : eventdesclist)
					{
						writer.addElement("canssEvent_eventDescription");
							writer.addElement("canssEvent_EventID", eventdesc.getEVENTID().toString());
							writer.addElement("canssEvent_Level", eventdesc.getLEVEL().toString());
							writer.addElement("canssEvent_EventName", eventdesc.getEVENTNAME());
							writer.addElement("canssEvent_OneLineDesc", eventdesc.getONELINEDESC());
						writer.closeElement();
					}
				}
			}
			writer.closeElement();
			writer.finish();
		}
	}
}